package com.kit.data.kitopeso.dialog;

import android.content.Context;
import android.content.DialogInterface;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.kit.data.kitopeso.R;
import com.kit.data.kitopeso.base.BaseDialog;
import com.kit.data.kitopeso.base.BaseParams;
import com.kit.data.kitopeso.databinding.KitoUpdateDialogBinding;
import com.kit.data.kitopeso.obj.KitoUpdateInfo;
import com.kit.data.kitopeso.tools.ResUtils;
import com.kit.data.kitopeso.tools.ViewUtils;


public class UpdateDialog extends BaseDialog<KitoUpdateDialogBinding> {
    public UpdateDialog(@NonNull Context context) {
        super(context);
    }

    public UpdateDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }

    protected UpdateDialog(@NonNull Context context, boolean cancelable, @Nullable DialogInterface.OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    @Override
    protected KitoUpdateDialogBinding initViewBinding(LayoutInflater inflater) {
        return KitoUpdateDialogBinding.inflate(inflater);
    }

    @Override
    protected void initView() {

        setCanceledOnTouchOutside(false);

        binding.tvColse.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ViewUtils.viewScale(v);
                dismiss();
                if (onBtnClickListener != null) {
                    onBtnClickListener.btnOnClickColse();
                }
            }
        });
        binding.tvBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ViewUtils.viewScale(v);
                if (onBtnClickListener != null) {
                    onBtnClickListener.btnOnClickOk();
                }
            }
        });

        binding.tvHit1.setText(Html.fromHtml(ResUtils.s(R.string.update_hit1)));
        binding.tvHit2.setText(ResUtils.s(R.string.update_hit2, BaseParams.getVersionName(getContext())));
        binding.tvHit2.setVisibility(View.GONE);

    }

    public void setData(KitoUpdateInfo info) {
        if (binding != null && info != null) {


            binding.tvVer.setText(ResUtils.s(R.string.update_subtitle, String.valueOf(info.getUpdateVer())));


            binding.tvContent.setText(info.getUpdateContent());


            if (info.getForceUpdate().equals("YES")) {
                binding.tvHit1.setVisibility(View.GONE);
                binding.tvColse.setVisibility(View.GONE);
                binding.tvHit2.setVisibility(View.VISIBLE);
            } else {
                binding.tvHit1.setVisibility(View.VISIBLE);
                binding.tvColse.setVisibility(View.VISIBLE);
            }

        }
    }

}
